package com.woniuxy.cq.phrase3.controller;


import com.woniuxy.cq.phrase3.common.Result;
import com.woniuxy.cq.phrase3.dao.MessageMapper;
import com.woniuxy.cq.phrase3.entity.Message;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @description:  消息通知
 * @param: null
 * @return:
 * @author Daniel
 * @date: 2020/9/9 20:17
 */
@RestController
@Slf4j
public class MessageController {
    @Autowired
    private MessageMapper messageMapper;

    @GetMapping("/message/getData")
    public Result getMessage(HttpSession session) {
        Integer userId = (Integer) session.getAttribute("userId");
        List<Message> message = messageMapper.getMessage(userId);
        return Result.success(message);
    }

    @PostMapping("/message/delete")
    public Result deleteMessage(HttpSession session) {
        Integer userId = (Integer) session.getAttribute("userId");
        String messageStatus = "clear";
        messageMapper.updateByuserId(userId, messageStatus);
        return Result.success();
    }
}

